package com.genius.util.Utils.BeanUtils;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;


public class DecomposeStation {
    private Class yourName;

    public DecomposeStation(Class name){
        this.yourName = name;
    }

    public DecomposeStation(String packPath){
        if(packPath!=null){
            try {
                this.yourName = Class.forName(packPath);
            }catch (ClassNotFoundException e){
                e.printStackTrace();
            }
        }
    }

    public Class getYourName(){
        return yourName;
    }

    public Constructor getConstructer(Class...args){
        Constructor constructor = null;
        try {
           constructor  = yourName.getConstructor(args);
        }catch (NoSuchMethodException e){
            e.printStackTrace();
        }
        return constructor;
    }


    public Method[] getAllMethod(){
        Method methods[] = yourName.getMethods();
        return  methods;
    }

    public Method getMethod(String methodName, Class...args){
        Method method = null;
        try {
            method = yourName.getDeclaredMethod(methodName,args);
        }catch (NoSuchMethodException e){
            e.printStackTrace();
        }
        return method;
    }

    public Field[] getField(){
        Field[] fields = yourName.getFields();
        return fields;
    }

    public Field[] getHeartField(){
        Field[] fields = yourName.getDeclaredFields();
        return fields;
    }

    public Field getField(String name){
        Field field = null;
        try {
            field = yourName.getDeclaredField(name);
        }catch (NoSuchFieldException e){
            e.printStackTrace();
        }
        return field;
    }

    public void changeYourHeart(Object you, Object value, Field field){
        field.setAccessible(true);
        try {
            field.set(you,value);
        }catch (IllegalAccessException e){
            e.printStackTrace();
        }
    }
}
